The present invention relates to a data caching method for caching data by employing a read buffer.
A conventional data caching method will be described with reference to the drawings. FIG. 6 is a block diagram illustrating an apparatus to which the conventional data caching method is applied. In FIG. 6, numeral 61 denotes a storage medium (e.g., a CD/DVD-ROM), numeral 62 denotes a read buffer, and numeral 63 denotes a computer.
FIGS. 7(a) to 7(d) are diagrams for explaining an example of changes in cache data in the conventional data caching method. Data stored in the read buffer 62, i.e., cache data, are changed in the order of FIGS. 7(a), 7(b), 7(c) and 7(d), in which numeral 62 denotes the read buffer, numeral 72 denotes read data, numeral 73 denotes pre-read data, numeral 74 denotes read data, and numeral 75 denotes pre-read data.
Next, the operation of the conventional data caching method will be described with reference to FIGS. 6 and 7(a)-7(d). When a computer 63 such as host computer issues a reading request for data at addresses 50 to 52 in a storage medium 61 such as a CD-ROM or DVD-ROM, the data at addresses 50 to 52 of the storage medium 61 are read out by a reading apparatus (not shown), and, as shown in FIG. 7(a), the read data 72 which have been read out from the storage medium 61 are buffered at the head of the read buffer 62 and are then transferred to the computer 63. Thereafter, data at address 53 and subsequent addresses of the storage medium 61 are pre-read by an amount which can be written in the available space of the read buffer 62. Then, as shown in FIG. 7(b), the pre-read data 73, i.e., data at addresses 53 to 101 which have been pre-read, are buffered up to the end position of the read buffer 62 so that the pre-read data 73 are made continuous with the read data 72.
Subsequently, when the computer 63 issues a reading request for data at addresses 48 to 50 of the storage medium 61, it is determined whether a cache hit occurs or not depending on whether or not data at address 48, as data at a reading starting position, are stored in the read buffer 62. Since the data at address 48 are not included in the read data 72 and the pre-read data 73 which have been stored in the read buffer 62, as shown in FIG. 7(b), the cache hit does not occur. Thus, data at addresses 48 to 50 of the storage medium 61 are read again, and, as shown in FIG. 7(c), the read data 74 which have been read out from the storage medium 61 are buffered at the head of the buffer memory 62 and are then transferred to the computer 63. Thereafter, data at addresses subsequent to address 50 of the storage medium 61 are pre-read by an amount which can be written in the available space of the read buffer 62. Then, as shown in FIG. 7(d), the pre-read data 75, i.e., data at addresses 51 to 99, are buffered up to the end position of the read buffer 62 so that the pre-read data 75 are made to be continuous with the read data 74.
As described above, in the conventional data caching method, even when part of data for which the computer 63 issues the reading requests have been previously stored in the read buffer 62, it is judged that the cache hit does not occur when data at the reading starting position are not stored, and reading is performed again from the storage medium 61 to rewrite all of data in the read buffer 62, thereby resulting in a lower efficiency.
Further, when the computer 63 issues a reading request for data which are not stored in the read buffer 62, even when the address of the data is slightly forward of the address of data that is stored in the read buffer 62, and there are few changes between pre-rewriting data and post-rewriting data, the data in the read buffer 62 are all rewritten. Accordingly, the efficiency is low.
The present invention is made in view of the above-described problems. The object of the present invention is to provide a data caching method which can utilize cache data efficiently and effectively.
According to the present invention, there is provided a data caching method for caching data by employing a read buffer when a computer issues a reading request for data stored in a storage medium. The data caching method comprises a step of determining whether the data that are stored in the storage medium, to which a reading request is issued are in cache hit with data which have already been buffered in the read buffer. The data caching method also comprises a buffering step of, when it is determined in the cache hit determination step that data for which the reading request is issued or a part thereof are not in cache hit, reading out only data, from the storage medium, which are not in cache hit among the data for which the reading request is issued to be buffered in the read buffer so as to be continuous with data which are in cache hit. The method also comprises a step of, after the buffering, transferring the data in the read buffer for which the reading request is issued to the computer. Further, the method comprises a pre-reading step of, after transferring the data for which the reading request is issued from the read buffer to the computer, pre-reading data which are stored in the storage medium that are subsequent to the data from the storage medium for which the reading request is issued, to be buffered in the read buffer so as to be continuous with the data in the read buffer for which the reading request is issued. Therefore, it is determined whether or not all of the data to which the computer issues the reading request are in cache hit, and only data which are not in cache hit are read out from the storage medium to be buffered in the read buffer. Therefore, there is no need to rewrite all of the data in the read buffer, and thus, it is possible to utilize cache data efficiently and effectively.
According to the present invention, in the aforementioned data caching method, in a case where data have already been stored in the read buffer so as to be continuous with the data for which the reading request is issued in the read buffer, the pre-reading step does not carry out the pre-reading. Therefore, there is no need to rewrite data which have already been stored in the read buffer, and thus, it is possible to utilize cache data efficiently and effectively.
According to the present invention, in the aforementioned data caching method, when it is determined in the cache hit determination step that at least rearmost (rear end position) data among the data for which the reading request is issued are in cache hit, the buffering step reads only data from the storage medium which are not in cache hit among the data for which the reading request is issued, and buffers the data immediately before the data which are in cache hit which have already been buffered in the read buffer so as to be followed by the data in cache hit. Therefore, even when the computer issues a reading request for data of addresses which precede the address(es) of the data to which the computer issues the reading request the last time, there is no need to re-read all of the data for which the reading request is issued from the storage medium, and the data can be transferred from the read buffer to the computer, whereby it is possible to utilize cache data efficiently and effectively.
According to the present invention, in the aforementioned data caching method, an arbitrarily-sized margin in which pre-read data are not recorded is provided at an end position of the read buffer. When the size of data which are not in cache hit among the data for which the reading request is issued is equal to or smaller than the size of the margin, the data which are not in cache hit are read out from the storage medium to be buffered in the margin so as to be continuous with the data in the read buffer. Therefore, there is no need to rewrite all of the data in the read buffer, whereby it is possible to utilize cache data efficiently and effectively.
According to the present invention, in the aforementioned data caching method, before the pre-reading step, the margin is set again immediately preceding the data for which the reading request is issued. Therefore, the margin is always provided at the end section of the data in the read buffer, whereby it is possible to utilize cache data efficiently and effectively.
According to the present invention, in the aforementioned data caching method, the size of the margin can be changed into an arbitrary size on the basis of a past buffering state. Therefore, the margin can always have an optimal size, whereby it is possible to utilize cache data efficiently and effectively.